;	BINTOBCD16
;   by Joe Pemberton
;size: 97 bytes
;
;input:
;de=number to convert
;
;returns (bcd16) as TEN THOUSANDS, THOUSANDS, HUNDREDS, TENS, ONES
;(bcd16string) contains the formatted bcd ascii string
;b = 0
;de = 0
;destroys af, bc, de, hl, ix
bintobcd16:
	push	de
	ld	hl,bcd16
	ld	de,bcd16+1
	ld	bc,10
	ld	(hl),0
	ldir
	pop	de
	ld	b,16
bcd16L:	ld	hl,bcd16
	push	bc
	ld	b,5
bcd16I:	ld	a,(hl)
	cp	5
	jr	c,bcd16a
	add	a,3
	ld	(hl),a
bcd16a:	inc	hl
	djnz	bcd16I
	dec	hl		;hl now points to the ONES
	ld	b,5
	sla	e
	rl	d
bcd16b:	rl	(hl)
	bit	4,(hl)
	jr	z,bcd16c
	res	4,(hl)
	scf
bcd16c:	dec	hl
	djnz	bcd16b
	pop	bc
	djnz	bcd16L
	inc	hl
	ld	ix,bcd16string
	ld	bc,(5*256)+0
bcd16d:	ld	a,(hl)
	add	a,$30
	ld	(ix+0),a
	cp	$30
	jr	nz,bcd16e
	bit	1,c
	jr	z,bcd16f
bcd16e:	inc	ix
	set	1,c
bcd16f:	inc	hl
	djnz	bcd16d
	ret